package cn.iocoder.yudao.module.biz.service.emergencyReservePlainDrill;

import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;

import java.util.*;
import cn.iocoder.yudao.module.biz.controller.admin.emergencyReservePlainDrill.vo.*;
import cn.iocoder.yudao.module.biz.dal.dataobject.emergencyReservePlainDrill.BizEmergencyReservePlainDrillDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;

import cn.iocoder.yudao.module.biz.convert.emergencyReservePlainDrill.BizEmergencyReservePlainDrillConvert;
import cn.iocoder.yudao.module.biz.dal.mysql.emergencyReservePlainDrill.BizEmergencyReservePlainDrillMapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.biz.enums.ErrorCodeConstants.*;

/**
 * 演练计划 Service 实现类
 *
 * @author 芋道源码
 */
@Service
@Validated
public class BizEmergencyReservePlainDrillServiceImpl implements BizEmergencyReservePlainDrillService {

    @Resource
    private BizEmergencyReservePlainDrillMapper emergencyReservePlainDrillMapper;

    @Override
    public String createEmergencyReservePlainDrill(BizEmergencyReservePlainDrillCreateReqVO createReqVO) {
        // 插入
        BizEmergencyReservePlainDrillDO emergencyReservePlainDrill = BizEmergencyReservePlainDrillConvert.INSTANCE.convert(createReqVO);
        emergencyReservePlainDrillMapper.insert(emergencyReservePlainDrill);
        // 返回
        return emergencyReservePlainDrill.getId();
    }

    @Override
    public void updateEmergencyReservePlainDrill(BizEmergencyReservePlainDrillUpdateReqVO updateReqVO) {
        // 校验存在
        this.validateEmergencyReservePlainDrillExists(updateReqVO.getId());
        // 更新
        BizEmergencyReservePlainDrillDO updateObj = BizEmergencyReservePlainDrillConvert.INSTANCE.convert(updateReqVO);
        emergencyReservePlainDrillMapper.updateById(updateObj);
    }

    @Override
    public void deleteEmergencyReservePlainDrill(String id) {
        // 校验存在
        this.validateEmergencyReservePlainDrillExists(id);
        // 删除
        emergencyReservePlainDrillMapper.deleteById(id);
    }

    private void validateEmergencyReservePlainDrillExists(String id) {
        if (emergencyReservePlainDrillMapper.selectById(id) == null) {
            throw exception(EMERGENCY_RESERVE_PLAIN_DRILL_NOT_EXISTS);
        }
    }

    @Override
    public BizEmergencyReservePlainDrillDO getEmergencyReservePlainDrill(String id) {
        return emergencyReservePlainDrillMapper.selectById(id);
    }

    @Override
    public List<BizEmergencyReservePlainDrillDO> getEmergencyReservePlainDrillList(Collection<String> ids) {
        return emergencyReservePlainDrillMapper.selectBatchIds(ids);
    }

    @Override
    public PageResult<BizEmergencyReservePlainDrillDO> getEmergencyReservePlainDrillPage(BizEmergencyReservePlainDrillPageReqVO pageReqVO) {
        return emergencyReservePlainDrillMapper.selectPage(pageReqVO);
    }

    @Override
    public List<BizEmergencyReservePlainDrillDO> getEmergencyReservePlainDrillList(BizEmergencyReservePlainDrillExportReqVO exportReqVO) {
        return emergencyReservePlainDrillMapper.selectList(exportReqVO);
    }

}
